<template>
  <div class="logbox">
    <header>
      <i class="el-icon-arrow-left" @click="$router.go(-1)"></i>
      <div>登录</div>
      <i></i>
    </header>
    <div class="login">
      <div class="input">
        <span>账号:</span>
        <input type="text" v-model="userinfo.username" />
      </div>
      <div class="input">
        <span>密码:</span>
        <input type="text" v-model="userinfo.password" />
      </div>
      <div class="btn" @click="login">
        登录
      </div>
      <p class="zhuce"><router-link to="reigist">立即注册</router-link></p>
    </div>
  </div>
</template>

<script>
import Vue from "vue";
import { Toast } from "vant";

Vue.use(Toast);
export default {
  data() {
    return {
      userinfo: {
        username: "",
        password: "",
      },
    };
  },
  methods: {
    login() {
      this.$store.dispatch("login", this.userinfo).then((res) => {
        if (res.code == 200) {
          Toast({
            message: "登陆成功",
            position: "top",
          });
          this.$router.push("/");
        } else {
          Toast({
            message: "账号或密码错误",
            position: "top",
          });
        }
      });
    },
  },
};
</script>

<style scoped>
.logbox {
  background-color: #ffffff;
  height: 100%;
}
.zhuce{
  width: 100%;
  text-align: center;
  margin: 0.5rem 0;
  color: #788299;
}
header {
  height: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 0.22rem;
  box-sizing: border-box;
  background-color: #ffffff;
}
header i {
  font-size: 0.48rem;
  flex: 1;
}
header div {
  font-size: 0.32rem;
  font-weight: bold;
  flex: 1;
  text-align: center;
}
.login {
  width: 5.82rem;
  height: 5.04rem;
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  margin: auto;
  margin-top: 2.64rem;
}
.input {
  width: 100%;
  height: 0.8rem;
  border-bottom: 1px solid #eceef1;
  font-size: 0.28rem;
  display: flex;
  align-items: center;
}
.input span {
  color: #788299;
  line-height: 0.8rem;
  margin-right: 0.2rem;
}
input {
  flex: 1;
  height: 0.76rem;
}
.btn {
  width: 100%;
  height: 0.76rem;
  text-align: center;
  line-height: 0.76rem;
  background-color: #33b17b;
  color: #ffffff;
  margin-top: 1.6rem;
  border-radius: 0.08rem;
}
</style>
